//
// Created by 11510 on 2024/7/10.
//

#ifndef REACTOR_V3_TCPSERVER_H
#define REACTOR_V3_TCPSERVER_H

#include "Acceptor.h"
#include "EventLoop.h"

class TcpServer {
private:
    Acceptor _acceptor;
    EventLoop _eventLoop;
public:
    TcpServer(const std::string &ip, unsigned short port) :
            _acceptor(ip, port),
            _eventLoop(_acceptor) {}

    ~TcpServer() = default;

    void start(){
        _acceptor.ready();
        _eventLoop.loop();
    }

    void stop(){
        _eventLoop.unloop();
    }

    void setAllCallback(EventLoop::TcpConnectionCallback &&cb1,
                        EventLoop::TcpConnectionCallback &&cb2,
                        EventLoop::TcpConnectionCallback &&cb3){
        _eventLoop.setOnNewConnectionCallback(std::move(cb1));
        _eventLoop.setOnMessageCallback(std::move(cb2));
        _eventLoop.setOnCloseCallback(std::move(cb3));
    }
};


#endif //REACTOR_V3_TCPSERVER_H
